<template>
  <!-- 管理员弹框 -->
  <a-modal
    :title="questionTitle"
    width="800px"
    centered
    :visible="questionVisible"
    :maskClosable="false"
    okText="确定"
    @ok="submitInform()"
    @cancel="closeDraw"
  >
    <div style="margin-top: 20px" class="table-content">
      <a-table
        bordered
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
        }"
        :columns="columns"
        :data-source="list"
        rowKey="id"
        :pagination="pagination"
      >
      </a-table>
    </div>
  </a-modal>
</template>

<script>
import { paging } from "assets/js/mixin";
import question from "@/assets/json/questionList.js";
export default {
  mixins: [paging],
  props: {
    //关闭弹框
    closeFunc: {
      type: Function,
      default: () => {},
    },
    questionVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      pagination: {
        //表格分页相关配置
        defaultPageSize: 5, 
        pageSizeOptions: ["5", "10"],
      },
      selectedRows: [],
      selectedRowKeys: [],
      keywords: "",
      columns: [
        {
          title: "序号",
          dataIndex: "id",
          scopedSlots: { customRender: "id" },
          sorter: (a, b) => a.id - b.id,
        },
        {
          title: "题目内容",
          dataIndex: "question",
        },
      ],
      list: question(),
      id: "",
      questionTitle: "添加题目",
    };
  },

  methods: {
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      console.log(this.selectedRows);
    },
    submitInform() {
      var select = {
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows,
      };
      this.$emit("selectQuestion", select);
      this.$emit("closeFunc");
    },
    //关闭弹框
    closeDraw() {
      this.$emit("closeFunc");
    },
  },
  watch: {
    questionVisible(n) {
      if (n) {
        //this.selectedRowKeys = JSON.parse(localStorage.getItem("selectKey"))
        if (localStorage.getItem("selectKey")) {
          this.selectedRowKeys = JSON.parse(localStorage.getItem("selectKey"));
        }
      } else {
      }
    },
  },
};
</script>

<style lang="stylus" scoped></style>